$().ready(function() {
	validateRule();
    $("#questionText").hide();
});

layui.use(['upload'], function () {
    var upload = layui.upload;
    upload.render({
        elem: '#btnUpload',
        url: '/jzApi/utils/fileImprot',
        timeout: 36000000,
        size: 1024 * 100,
        accept: 'file',
        // exts: 'docx|doc|xlsx|pdf|ppt',
        done: function (r) {
            $("#fileRoute").val(r.data);
            $("#test").html(subFileName(r.data));
        },
        error: function (r) {
            layer.msg(r.msg);
        }
    });
});
$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/jzweb/majorItemBank/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
            teacherMajorId : {
				required : true
			},
            rightKey : {
                required : true
            },
            type : {
                required : true
            },
            topicContent : {
                required : true
            },
            topicAnalysis : {
                required : false
            },
            score : {
                required : true
            },
		},
		messages : {
            teacherMajorId : {
				required : icon + "请选择教学专业"
			},
            rightKey: {
                required : icon + "请输入正确答案"
            },
            type : {
                required : icon + "请选择题目类型"
            },
            topicContent : {
                required : icon + "请输入题目内容名"
            },
            topicAnalysis : {
                required : icon + "请输入题目解析"
            },
            score : {
                required : icon + "请输入分值"
            }
		}
	})
}

$(function () {
    $("#resourceType").change(function () {
        $("#enclosure").val("");
        $("#test").html("");
        var type = $(this).val();
        if (type!=0&&type!='') {
            $("#resourse").show();
            $("#btnUpload").show()
        } else {
            $("#resourse").hide();
        }
    });
    $("#type").change(function () {
        var type = $(this).val();
        console.log("type:"+type);
        if (type != '' && type!=null && type!=undefined && type!='undefined') {
            if (type!=4&&type!='') {
                $(".otherType").show();
                $("#questionText").hide();
            } else {
                $(".otherType").hide();
                $("#questionText").show();
            }
        } else {
            $(".otherType").hide();
           // $("#questionText").show();
        }
    });
});